package com.banmao.c03_baseUsage.config;

import com.banmao.c03_baseUsage.entity.Dog;
import com.banmao.c03_baseUsage.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;

@Slf4j
public class BeanConfig {

    @Bean
    Dog dog() {
        log.info("dog init...");
        Dog dog = new Dog();
        dog.setAge(4);
        dog.setName("小白");
        return dog;
    }

    @Bean
    User user(Dog dog) {
        User user = new User();
        user.setAge(29);
        user.setName("赵六");
        user.setDog(dog);

        // 在 @Bean 中调用另一个 @Bean 方法，会导致一个 Bean 被初始化两次，导致单例失效
//        user.setDog(dog());

        return user;
    }

}
